package com.universest.swordholder.aitool

import com.universest.swordholder.model.user.UserManager
import kotlinx.coroutines.flow.firstOrNull

suspend fun createAiTask(name: String): PromptTask{
    val apiKey = UserManager.instance.getUserConfigManager().getConfig("deepseekApiKey", "").firstOrNull()?:""
    if(apiKey.isEmpty()){
        throw Exception("功能暂不可用，请在[我的]->[应用配置]中配置DeepSeek API Key")
    }
    val model = "deepseek-reasoner"
    val url = UserManager.instance.getUserConfigManager().getConfig("deepseekModelUrl", Constants.DEEPSEEK_API_URL).firstOrNull() ?: Constants.DEEPSEEK_API_URL
    if (!url.matches(Regex("^https?://.+"))){
        throw Exception("功能暂不可用，请在[我的]->[应用配置]中配置格式正确的模型地址。")
    }
    val api = DeepSeekApi(apiKey, model, url)
    api.maxTokens = 64000
    return PromptTask(name, api)
}